package admin

import (
	. "go-caipu/pkg/services/sqlstore/migrator"
)

func AddOperaLogMigrations(mg *Migrator) {
	userV1 := Table{
		Name: "sys_opera_log",
		Columns: []*Column{
			{Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
			{Name: "module", Type: DB_NVarchar, Length: 128, Nullable: false},
			{Name: "description", Type: DB_NVarchar, Length: 128, Nullable: false},
			{Name: "os", Type: DB_NVarchar, Length: 128, Nullable: false},
			{Name: "address", Type: DB_NVarchar, Length: 300, Nullable: false},
			{Name: "browser", Type: DB_NVarchar, Length: 128, Nullable: true},
			{Name: "ip", Type: DB_NVarchar, Length: 64, Nullable: true},
			{Name: "method", Type: DB_NVarchar, Length: 128, Nullable: true},
			{Name: "request_body", Type: DB_Blob, Nullable: true},
			{Name: "request_headers", Type: DB_Blob, Nullable: true},
			{Name: "request_url", Type: DB_NVarchar, Length: 200, Nullable: true},
			{Name: "response_body", Type: DB_Blob, Nullable: true},
			{Name: "response_headers", Type: DB_Blob, Nullable: true},
			{Name: "status_code", Type: DB_Int, Length: 128, Nullable: true},
			{Name: "remark", Type: DB_NVarchar, Length: 600, Nullable: true},
			{Name: "trace_id", Type: DB_NVarchar, Length: 64, Nullable: true},
			{Name: "time_taken", Type: DB_Int, Length: 128, Nullable: true},
			{Name: "create_by", Type: DB_Varchar, Length: 100, Nullable: true},
			{Name: "create_user", Type: DB_Varchar, Length: 100, Nullable: true},
			{Name: "created_at", Type: DB_DateTime, Nullable: false},
			{Name: "updated_at", Type: DB_DateTime, Nullable: true},
		},
		Indices: []*Index{
			{Cols: []string{"created_at", "create_by"}, Type: UniqueIndex},
		},
	}
	//create table
	mg.AddMigration("create sys_opera_log table", NewAddTableMigration(userV1))
}
